<!DOCTYPE html>
<html lang="en">
    <head>
        <meta charset="utf-8">
        <title>
    Scheduled Task Error : Forums : PythonAnywhere
</title>
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
        <meta name="description" content="Forums : PythonAnywhere">
        <meta name="author" content="PythonAnywhere LLP">
        <meta name="google-site-verification" content="O4UxDrfcHjC44jybs2vajc1GgRkTKCTRgVzeV6I9V14" />

        <!-- Le styles -->
        <link href="/static/bootstrap/css/bootstrap.css" rel="stylesheet">
        <link href="/static/bootstrap/css/bootstrap-responsive.css" rel="stylesheet">
        <link href="/static/anywhere/styles/bootstrap_base.css" rel="stylesheet">
        
    
    <link rel="stylesheet" href="/static/anywhere/styles/forums.css" type="text/css" media="screen" charset="utf-8" />

    <link rel="stylesheet" href="/static/pygments/style.css" type="text/css" media="screen" charset="utf-8" />

        <link rel="stylesheet" href="/static/jquery/jquery-ui-1.8.11.custom.css" type="text/css" media="screen" charset="utf-8" />
        
    
    <link rel="alternate" type="application/rss+xml" title="RSS" href="/forums/topic/847/rss" />

        <style type="text/css">
            body {
                height: auto;
            }
        </style>
        <!-- Le HTML5 shim, for IE6-8 support of HTML5 elements -->
        <!--[if lt IE 9]>
        <script src="//html5shim.googlecode.com/svn/trunk/html5.js"></script>
        <![endif]-->

        <!-- Le fav and touch icons -->
        <link rel="apple-touch-icon" href="images/apple-touch-icon.png">
        <link rel="apple-touch-icon" sizes="72x72" href="images/apple-touch-icon-72x72.png">
        <link rel="apple-touch-icon" sizes="114x114" href="images/apple-touch-icon-114x114.png">
    </head>

     <body>
        <div class="navbar navbar-fixed-top">
            <div class="navbar-inner">
                <div id="id_internal_nav_bar_container" class="container">
                    <a class="btn btn-navbar" data-toggle="collapse" data-target=".nav-collapse">
                    <span class="icon-bar"></span>
                    <span class="icon-bar"></span>
                    <span class="icon-bar"></span>
                    </a>
                    <a class="brand" href="/"><img id="id_logo" src="/static/anywhere/images/logo-234x35.png" height="35" title="PythonAnywhere logo" alt="PythonAnywhere logo" /></a>
                    <div class="nav-collapse">
                        <ul id="id_header_links" class="nav">
                            <li><a id="id_feedback_link" class='feedback_link' href="">Send feedback</a></li>
                            <li><a id="id_forums_link" href="/forums/">Forums</a></li>
                            <li><a href="/wiki/" id="id_help_link">Help</a></li>
                            <li><a href="http://blog.pythonanywhere.com/" id="id_blog_link">Blog</a></li>
                            
                            
                                <li><a style="font-weight: bold;" href="/pricing/" id="id_pricing_link">Pricing & signup</a></li>
                                <li><a href="/login/?next=/forums/topic/847/" id="id_login_link">Log in</a></li>
                            
                        </ul>
                    </div>
                </div>
            </div>
        </div>

        <div class="top-container" id="id_dummy"></div>

        

        
    
    <div class="container">
        <div class="row">
            <div class="span8 offset3">
                <h1>PythonAnywhere Forums</h1>
            </div>
        </div>



    <div class="row">
        <div class="span8 offset3">
            <p>
                <a href="/forums/start_topic/" id="id_start_new_topic">Start a new topic</a> |
                <a href="/forums/">Back to all topics</a> |
                <a href="/forums/topic/847/rss">This topic's RSS</a>
            </p>
        </div>
    </div>
    <div class="row">
        <div class="span8 offset3 topic">
            <h2>Scheduled Task Error</h2>
        </div>
    </div>

    
        <div class="row">
            <div id="id_post_5985" class="span8 offset3 post">
                <div class="row">
                    <div id="id_post_5985_content_text" class="span8">
                        <p>I've got a scheduled daily task that's been largely working fine for about two weeks now, but for one error, the log of which seems to be as follows:</p>
<div class="codehilite"><pre>/bin/bash: line 0: cd: /home/Johz: Stale NFS file handle
python: can&#39;t open file &#39;nsdb/nsdb/unravel_dump.py&#39;: [Errno 2] No such file or directory

2013-08-13 13:41:03 -- Completed task, took 0.00 seconds, return code was 2.
</pre></div>


<p>My understanding of linux systems isn't great enough to entirely understand what's happening here, but as far as I can tell the scheduler couldn't cd into my home directory for some reason.  Can anyone advise what's happened, if it's likely to happen again, and how I might deal with it next time?</p>
                    </div>
                </div>
                <div class="row">
                    <div class="span7 post_metadata">
                        <span id="id_post_5985_creator_details">
                            
                                
                                    <img src="/static/anywhere/images/star.gif" alt="Beloved premium user" title="Beloved premium user"/>
                                
                            
                            Johz
                            |
                            2
                            posts
                            |
                            
                        </span>
                        <span id="id_post_5985_created_date">
                            Aug. 19, 2013, 6:57 p.m.
                        </span>
                        |
                        <a href="https://www.pythonanywhere.com/forums/topic/847/#id_post_5985">permalink</a>
                    </div>
                    <div class="span1">
                        
                    </div>
                </div>
            </div>
        </div>
    
        <div class="row">
            <div id="id_post_5986" class="span8 offset3 post">
                <div class="row">
                    <div id="id_post_5986_content_text" class="span8">
                        <p>Hm, that looks most likely to be caused by an issue on the server. A stale NFS handle occurs when the client is holding a reference to something that's whisked away from under it by another client. The most common cause is when a client changes into a working directory which is then deleted - when the client then tries to access something relative to its current directory (including <code>.</code> and <code>..</code>) then it gets the stale handle error. In this case the "client" is in fact part of the environment that's running your script, so this isn't related directly to some issue in your code.</p>
<p>I suspect it's most likely that your script was kicked off just as some sort of server maintenance was going on which caused this issue, but the devs can probably shed more light on probable causes. My advice to try and minimise the problem is to always work with absolute path names, never relative to the current directory (i.e. all path names should start with <code>/home/Johz</code> for files inside your home directory). Without knowing the exact cause I don't know how much this will help, but it's generally good practice anyway. To resolve a relative path name (e.g. <code>./mydir/file.txt</code>) the current working directory must be accessed, and if the current directory has become stale at any point since the script was started then this will fail. Absolute path names, however, involve following the path from <code>/</code> (always accessible) down to the directory each time it's accessed. So, if the directory were to briefly disappear and reappear under the same name (but a different underlying object), an absolute access wouldn't be affected but a relative access would become stale. I probably haven't explained that very well, but I did my best. I managed to avoid using the term <em>inode</em>, at least. Damn, I was doing so well... (^_^)</p>
<p>Aside from that, occasional glitches are just a hazard of running 24/7 on a managed service which must periodically undergo maintenance and repair - as long as you write your script to be tolerant of failures at any point (i.e. don't leave anything lying around which will prevent it running next time) then it shouldn't be more than a minor annoyance unless it happens frequently.</p>
<p>You can read <a href="http://www.cyberciti.biz/tips/nfs-stale-file-handle-error-and-solution.html">this page</a> for a little more background on the error if you're interested, but it's not going to be of any actual help because it's aimed at operators/admins.</p>
                    </div>
                </div>
                <div class="row">
                    <div class="span7 post_metadata">
                        <span id="id_post_5986_creator_details">
                            
                                
                                    <img src="/static/anywhere/images/star.gif" alt="Beloved premium user" title="Beloved premium user"/>
                                
                            
                            Cartroo
                            |
                            638
                            posts
                            |
                            
                        </span>
                        <span id="id_post_5986_created_date">
                            Aug. 19, 2013, 10:04 p.m.
                        </span>
                        |
                        <a href="https://www.pythonanywhere.com/forums/topic/847/#id_post_5986">permalink</a>
                    </div>
                    <div class="span1">
                        
                    </div>
                </div>
            </div>
        </div>
    
        <div class="row">
            <div id="id_post_5991" class="span8 offset3 post">
                <div class="row">
                    <div id="id_post_5991_content_text" class="span8">
                        <p>Cartroo's advice, as usual, is excellent.  I learned something new.  Absolute paths and glitch-tolerant scripts are the way to go...</p>
                    </div>
                </div>
                <div class="row">
                    <div class="span7 post_metadata">
                        <span id="id_post_5991_creator_details">
                            
                                <img src="/static/anywhere/images/staff.png" alt="Staff" title="Staff"/>
                            
                            harry
                            |
                            376
                            posts
                            |
                            
                                PythonAnywhere staff
                                |
                            
                        </span>
                        <span id="id_post_5991_created_date">
                            Aug. 20, 2013, 12:44 p.m.
                        </span>
                        |
                        <a href="https://www.pythonanywhere.com/forums/topic/847/#id_post_5991">permalink</a>
                    </div>
                    <div class="span1">
                        
                    </div>
                </div>
            </div>
        </div>
    
        <div class="row">
            <div id="id_post_5998" class="span8 offset3 post">
                <div class="row">
                    <div id="id_post_5998_content_text" class="span8">
                        <p>Another thing to consider is that relative paths are always relative to something, typically the current working directory of the process. So, using relative paths can alter the execution of your script if you execute it from different locations. Scheduled tasks should always execute from the same location, but it's conceivable (though highly unlikely) that the devs might change where this is. In general, you should avoid making assumptions about the working directory (and <code>PATH</code>, come to that) wherever possible.</p>
<p>As an aside, if you're stuck with relative paths (typically due to user configuration or similar) then you can easily convert them to absolute paths with Python's <a href="http://docs.python.org/2/library/os.path.html#os.path.abspath"><code>os.path.abspath()</code></a> - this function takes a single argument of a string containing a path (which may be absolute or relative to the current working directory) and always returns the equivalent absolute path. This shouldn't be confused with the similar-sounding <a href="http://docs.python.org/2/library/os.path.html#os.path.normpath"><code>os.path.normpath()</code></a>, which just attempts to "simplify" the path by removing redundant items, but doesn't change whether the path is relative or absolute.</p>
<p>For example:</p>
<div class="codehilite"><pre><span class="o">&gt;&gt;&gt;</span> <span class="kn">import</span> <span class="nn">os</span>
<span class="o">&gt;&gt;&gt;</span> <span class="n">os</span><span class="o">.</span><span class="n">getcwd</span><span class="p">()</span>
<span class="s">&#39;/home/myuser&#39;</span>
<span class="o">&gt;&gt;&gt;</span> <span class="n">os</span><span class="o">.</span><span class="n">path</span><span class="o">.</span><span class="n">abspath</span><span class="p">(</span><span class="s">&quot;../user123/../user456/file.txt&quot;</span><span class="p">)</span>
<span class="s">&#39;/home/user456/file.txt&#39;</span>
<span class="o">&gt;&gt;&gt;</span> <span class="n">os</span><span class="o">.</span><span class="n">path</span><span class="o">.</span><span class="n">normpath</span><span class="p">(</span><span class="s">&quot;../user123/../user456/file.txt&quot;</span><span class="p">)</span>
<span class="s">&#39;../user456/file.txt&#39;</span>
</pre></div>


<p>Sorry Johz, you probably never expected your post to provoke such a deluge of verbiage! (^_^)</p>
                    </div>
                </div>
                <div class="row">
                    <div class="span7 post_metadata">
                        <span id="id_post_5998_creator_details">
                            
                                
                                    <img src="/static/anywhere/images/star.gif" alt="Beloved premium user" title="Beloved premium user"/>
                                
                            
                            Cartroo
                            |
                            638
                            posts
                            |
                            
                        </span>
                        <span id="id_post_5998_created_date">
                            Aug. 21, 2013, 7:04 a.m.
                        </span>
                        |
                        <a href="https://www.pythonanywhere.com/forums/topic/847/#id_post_5998">permalink</a>
                    </div>
                    <div class="span1">
                        
                    </div>
                </div>
            </div>
        </div>
    

    




        <div id="id_footer" class="container">

            <footer id="id_copyright_div">
                <p>
                    Copyright &copy; 2013 PythonAnywhere LLP
                    &mdash;
                    <a href="/terms/">Terms</a>
                    &mdash;
                    <a href="/privacy/">Privacy</a><br/>
                    "Python" is a registered trademark of the Python Software Foundation.
                </p>
            </footer>

        </div>

        
        

        <div id="id_feedback_dialog" title="Help us improve" style="display:none">
    <div id="id_feedback_dialog_blurb_big" class="dialog_blurb_big">
        It's always a pleasure to hear from you!
    </div>
    <div id="id_feedback_dialog_blurb_small">
        Ask us a question, or tell us what you love or hate about PythonAnywhere.<br/>
        We'll get back to you over email ASAP.
    </div>
    <textarea id="id_feedback_dialog_text" rows="6"></textarea>
    <input id="id_feedback_dialog_email_address" type="text" class="default_prompt"/>
    <div id="id_feedback_dialog_error" class="pa_hidden">
        Sorry, there was an error connecting to the server. <br/>Please try again in a few moments...
    </div>
    <div class="dialog_buttons">
        <img id="id_feedback_dialog_spinner" src="/static/anywhere/images/spinner-small.gif" />
        <button class="btn btn-primary" id="id_feedback_dialog_ok_button">OK</button>
        <button class="btn" id="id_feedback_dialog_cancel_button">Cancel</button>
    </div>
</div>


        <!-- Le javascript
        ================================================== -->
        <!-- Placed at the end of the document so the pages load faster -->
        <script type="text/javascript" src="/static/jquery/jquery-1.7.1.min.js"></script>
        <script type="text/javascript" src="/static/jquery/jquery-ui-1.8.11.custom.min.js"></script>
        <script src="/static/bootstrap/js/bootstrap-transition.js"></script>
        <script src="/static/bootstrap/js/bootstrap-alert.js"></script>
        <script src="/static/bootstrap/js/bootstrap-modal.js"></script>
        <script src="/static/bootstrap/js/bootstrap-dropdown.js"></script>
        <script src="/static/bootstrap/js/bootstrap-scrollspy.js"></script>
        <script src="/static/bootstrap/js/bootstrap-tab.js"></script>
        <script src="/static/bootstrap/js/bootstrap-tooltip.js"></script>
        <script src="/static/bootstrap/js/bootstrap-popover.js"></script>
        <script src="/static/bootstrap/js/bootstrap-button.js"></script>
        <script src="/static/bootstrap/js/bootstrap-collapse.js"></script>
        <script src="/static/bootstrap/js/bootstrap-carousel.js"></script>
        <script src="/static/bootstrap/js/bootstrap-typeahead.js"></script>

        <script type="text/javascript">
            var urls = {};
            var Anywhere = {};
            Anywhere.urls = {};
        </script>
        <script type="text/javascript" src="/static/anywhere/scripts/ajax_utils.js"></script>

        <script type="text/javascript" src="/static/anywhere/scripts/feedback_dialog.js"></script>
        
        <script type="text/javascript">
            $(function() {
                $.extend(
                    urls,
                    {
                        feedback: '/feedback/submit/'
                    }
                );
                
                    Anywhere.FeedbackDialog.Initialise(urls, true);
                
            });
        </script>

        <script type="text/javascript">

            var _gaq = _gaq || [];
            _gaq.push(['_setAccount', 'UA-18014859-6']);
            _gaq.push(['_trackPageview']);

            (function() {
                var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
                ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
                var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
            })();

        </script>

        



    </body>
</html>
